package com.tiendung.basicviewdemo;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class DemSoActivity extends Activity {

	int timeOut;
	EditText txtTime;
	EditText txtA;
	EditText txtB;
	TextView txtKQ;
	EditText txtResult;
	Random random = new Random();
	int soA, soB;

	public void startGame(View v) {
		txtTime = (EditText) findViewById(R.id.txtTime);
		txtTime.setEnabled(false);
		timeOut = Integer.parseInt(txtTime.getText().toString());
		txtA = (EditText) findViewById(R.id.txtSoA);
		txtB = (EditText) findViewById(R.id.txtSoB);
		txtKQ = (TextView) findViewById(R.id.txtKQ);
		txtResult.setEnabled(true);

		
		Handler countDown = new Handler() {
			int t = timeOut;

			public void handleMessage(android.os.Message msg) {
				if (t == -1) {
					EditText txtResult = (EditText) findViewById(R.id.txtResult);
					txtTime.setEnabled(true);
					txtResult.setEnabled(false);
					Button btnOK = (Button) findViewById(R.id.btnSubmit);
					btnOK.setEnabled(false);
					return;
				}

				txtTime.setText(t-- + "");
				this.sendEmptyMessageDelayed(0, 1000);
			}
		};
		countDown.sendEmptyMessage(0);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.game_dem_so);
		
		txtResult = (EditText) findViewById(R.id.txtResult);
		btnOK=findViewById(R.id.btnSubmit);
	}
}
